/**
 * Created by Administrator on 2019/4/1.
 */
var $$scope;
var dataInit;
function addRec($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $$scope = $scope;
    //提交流程
    $scope.receiveSubmit = function () {
        CertusJsonAjax.ajaxNode("receiveSubmit", $scope.material, function (res) {

            if (res.data && res.data == "success") {
                findBacklogPersonHead($CertusFormAjax, "")
            }
        })
    }

    //监控 招待 报销 展示 隐藏
    $$scope.$watch("receptshow",function(n,o,c){
        //每次 关闭的时候

        if(n == false && o && o == true){
            $$scope.receptItem = {};
        }
    })

    //初始化 selectpage
    CertusJsonAjax.ajax("relatedUser",{name:"%"},function(res){

        $('#selectPageRecieve').bSelectPage({
            showField: 'userName',
            keyField: 'userId',
            data: res.data,
            multiple: true,
            eSelect : function(data){

            },
        });
    })


    //初始化 表格
    var letOption = {
        lang: 'zh-cn',
        ajaxLoad: false,
        // loadURL:'url',
        exportFileName: '领用列表',
        datas: [],
        columns: letColumns,
        gridContainer: 'letContainer',
        toolbarContainer: 'letToolBarContainer',
        tools: '',
        pageSize: 100,
        pageSizeLimit: [10, 15, 20]
    };
    dataInit = $.fn.dlshouwen.grid.init(letOption);
    dataInit.load();

    //将内容  全部 发送到
    $scope.addItemMater = function(){
        if(certusValidateNotnullPolyfill()){
            //添加 当前 item 进入
            // $$scope.materialItem;

            // $scope.materialItem.
            $scope.materialItem.id = uuid();
            dataInit.exhibitDatas.push($scope.materialItem);
            dataInit.refresh(false);
            $scope.materialItem = {};
            shLet();
        }
    }

    //提交 并 保存 相关数据
    $scope.receiveSubmit = function(){
        if(certusValidateNotnull()){
            $scope.material.items = dataInit.exhibitDatas;
            $scope.material.recepts = $scope.receptItem;
            CertusJsonAjax.ajax("materialSubmit",$scope.material,function(res){
                layer.msg(res.data);
            })
        }
    }
}

